<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>dexterind-wifi.h</h1>  </div>
</div>
<div class="contents">
<a href="dexterind-wifi_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment"></span>
<a name="l00002"></a>00002 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00003"></a>00003 <span class="comment"></span><span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">//                 Setup for Wifi Sensor</span>
<a name="l00005"></a>00005 <span class="comment">//                 Sets up flow control</span>
<a name="l00006"></a>00006 <span class="comment">// Script for connecting to internet</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// ate0     // Turn off the echo.</span>
<a name="l00009"></a>00009 <span class="comment">// at&amp;k1    // Enable software flow control.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// at+wauth=1 // Authentication mode: open</span>
<a name="l00012"></a>00012 <span class="comment">// at+wwep1=0fb3ba79eb  // Set WEP key</span>
<a name="l00013"></a>00013 <span class="comment">// at+wa=NPX97    // Connect to the SSID</span>
<a name="l00014"></a>00014 <span class="comment">// at+ndhcp=1   // Enable DHCP &lt;Dynamic Host Configuration Protocol&gt;</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016 <span class="comment">// at+dnslookup=www.dexterindustries.com  // Lookup the DNS configuration.</span>
<a name="l00017"></a>00017 <span class="comment">//</span><span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="preprocessor">#pragma systemFile</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00022"></a>00022 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#endif</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span>
<a name="l00026"></a>00026 <span class="preprocessor">#ifndef __RS485_H__</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common-rs485_8h.html" title="Commonly used RS485-related functions used by drivers.">common-rs485.h</a>&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a><a class="code" href="dexterind-wifi_8h.html#ae2169453362dc55e2eaf6d41353864d9">00030</a> <span class="preprocessor">#define DEBUG_WIFI 1</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="dexterind-wifi_8h.html#a814daea84daef60fa4de30ba23e7d611">00033</a> <span class="keywordtype">long</span> <a class="code" href="dexterind-wifi_8h.html#a814daea84daef60fa4de30ba23e7d611">nRcvChars</a> = 0;
<a name="l00034"></a><a class="code" href="dexterind-wifi_8h.html#a9e6f17494d1421464ef6545fba911512">00034</a> ubyte <a class="code" href="dexterind-wifi_8h.html#a9e6f17494d1421464ef6545fba911512">BytesRead</a>[8];
<a name="l00035"></a><a class="code" href="dexterind-wifi_8h.html#aed83add5a4718b7ad3ab319ec15c075b">00035</a> <span class="keywordtype">char</span> <a class="code" href="dexterind-wifi_8h.html#aed83add5a4718b7ad3ab319ec15c075b">linefeed</a>[] = {0x0A};
<a name="l00036"></a><a class="code" href="dexterind-wifi_8h.html#a4745cd95697bdf771f54d46c6bcde5e0">00036</a> <span class="keywordtype">char</span> <a class="code" href="dexterind-wifi_8h.html#a4745cd95697bdf771f54d46c6bcde5e0">beginmarker</a>[] = {27, <span class="charliteral">&#39;S&#39;</span>, 0};
<a name="l00037"></a><a class="code" href="dexterind-wifi_8h.html#a1c3b42d561f1bb31a7235f49685bd366">00037</a> <span class="keywordtype">char</span> <a class="code" href="dexterind-wifi_8h.html#a1c3b42d561f1bb31a7235f49685bd366">endmarker</a>[] = {27, <span class="charliteral">&#39;E&#39;</span>, 0};
<a name="l00038"></a>00038 
<a name="l00039"></a><a class="code" href="dexterind-wifi_8h.html#accd447f37bc9ab0177af50148fee91b0">00039</a> <span class="keywordtype">long</span> <a class="code" href="dexterind-wifi_8h.html#accd447f37bc9ab0177af50148fee91b0">DWIFI_baudRates</a>[] = {9600, 19200, 38400, 57600, 115200, 230400,460800, 921600};
<a name="l00040"></a><a class="code" href="dexterind-wifi_8h.html#af42cc903eee7724d9b68fdaedbdcf312">00040</a> <span class="keywordtype">string</span> <a class="code" href="dexterind-wifi_8h.html#af42cc903eee7724d9b68fdaedbdcf312">DWIFIscratchString</a>;
<a name="l00041"></a><a class="code" href="dexterind-wifi_8h.html#a92597d8032c00de74b8f7e830f6b9e2e">00041</a> <a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> <a class="code" href="dexterind-wifi_8h.html#a92597d8032c00de74b8f7e830f6b9e2e">DWIFIscratchArray</a>;
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="comment"></span>
<a name="l00044"></a>00044 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00045"></a>00045 <span class="comment"></span><span class="comment">//</span>
<a name="l00046"></a>00046 <span class="comment">//  Setup High Speed on Port 4.</span>
<a name="l00047"></a>00047 <span class="comment">//</span><span class="comment"></span>
<a name="l00048"></a>00048 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00049"></a><a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">00049</a> <span class="comment"></span><span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> &amp;readdata, <span class="keywordtype">char</span> * caller = NULL)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051   <span class="keywordtype">int</span> len;
<a name="l00052"></a>00052   <span class="comment">// Read the RX buffer, but only wait 50ms max.</span>
<a name="l00053"></a>00053   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(readdata, len, 50))
<a name="l00054"></a>00054     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00055"></a>00055 
<a name="l00056"></a>00056   <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00057"></a>00057     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00058"></a>00058 
<a name="l00059"></a>00059   <span class="keywordflow">if</span> ((<a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)readdata, <span class="stringliteral">&quot;OK&quot;</span>) &gt; -1) || (<a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)readdata, <span class="stringliteral">&quot;0&quot;</span>) &gt; -1))
<a name="l00060"></a>00060   {
<a name="l00061"></a>00061     <span class="keywordflow">if</span> (caller != NULL)
<a name="l00062"></a>00062       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult %s SUCCESS&quot;</span>, caller);
<a name="l00063"></a>00063     <span class="keywordflow">else</span>
<a name="l00064"></a>00064       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult SUCCESS&quot;</span>);
<a name="l00065"></a>00065     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00066"></a>00066   }
<a name="l00067"></a>00067   <span class="keywordflow">else</span>
<a name="l00068"></a>00068   {
<a name="l00069"></a>00069     <span class="keywordflow">if</span> (caller != NULL)
<a name="l00070"></a>00070       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult %s FAILURE&quot;</span>, caller);
<a name="l00071"></a>00071     <span class="keywordflow">else</span>
<a name="l00072"></a>00072       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult FAILURE&quot;</span>);
<a name="l00073"></a>00073     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00074"></a>00074   }
<a name="l00075"></a>00075 }
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="dexterind-wifi_8h.html#a46794d18a9fe228bc540688ddf103967">00078</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> &amp;readdata, <span class="keywordtype">int</span> timeout, <span class="keywordtype">char</span> * caller = NULL)
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080   <span class="keywordtype">int</span> len;
<a name="l00081"></a>00081   <span class="comment">// Read the RX buffer, but only wait 50ms max.</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   <span class="comment">// writeDebugStreamLine(&quot;DWIFIcheckResult with extra timeout&quot;);</span>
<a name="l00084"></a>00084 
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(readdata, len, timeout))
<a name="l00086"></a>00086     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088   <span class="keywordflow">if</span> (len &lt; 1)
<a name="l00089"></a>00089     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00090"></a>00090 
<a name="l00091"></a>00091   <span class="keywordflow">if</span> ((<a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)readdata, <span class="stringliteral">&quot;OK&quot;</span>) &gt; -1) || (<a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)readdata, <span class="stringliteral">&quot;0&quot;</span>) &gt; -1))
<a name="l00092"></a>00092   {
<a name="l00093"></a>00093     <span class="keywordflow">if</span> (caller != NULL)
<a name="l00094"></a>00094       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult %s SUCCESS&quot;</span>, caller);
<a name="l00095"></a>00095     <span class="keywordflow">else</span>
<a name="l00096"></a>00096       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult SUCCESS&quot;</span>);
<a name="l00097"></a>00097     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00098"></a>00098   }
<a name="l00099"></a>00099   <span class="keywordflow">else</span>
<a name="l00100"></a>00100   {
<a name="l00101"></a>00101     <span class="keywordflow">if</span> (caller != NULL)
<a name="l00102"></a>00102       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult %s FAILURE&quot;</span>, caller);
<a name="l00103"></a>00103     <span class="keywordflow">else</span>
<a name="l00104"></a>00104       writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIcheckResult FAILURE&quot;</span>);
<a name="l00105"></a>00105     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00106"></a>00106   }
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 
<a name="l00110"></a><a class="code" href="dexterind-wifi_8h.html#a8a85998241ae167643f7cd8a3517a512">00110</a> <span class="keywordtype">int</span> <a class="code" href="dexterind-wifi_8h.html#a8a85998241ae167643f7cd8a3517a512">checkFailure</a>() {
<a name="l00111"></a>00111   ubyte currByte[] = {0};
<a name="l00112"></a>00112   ubyte prevByte[] = {0};
<a name="l00113"></a>00113 
<a name="l00114"></a>00114   <span class="keywordflow">while</span> (nxtGetAvailHSBytes() == 0) wait1Msec(5);
<a name="l00115"></a>00115 
<a name="l00116"></a>00116   <span class="keywordflow">while</span> (nxtGetAvailHSBytes() &gt; 0) {
<a name="l00117"></a>00117     nxtReadRawHS(&amp;currByte[0], 1);
<a name="l00118"></a>00118     <span class="keywordflow">if</span> ((prevByte[0] == 27) &amp;&amp; (currByte[0] == <span class="charliteral">&#39;F&#39;</span>))
<a name="l00119"></a>00119       <span class="keywordflow">return</span> 1;
<a name="l00120"></a>00120     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((currByte[0] &gt; <span class="charliteral">&#39;0&#39;</span>) &amp;&amp; (currByte[0] &lt; <span class="charliteral">&#39;7&#39;</span>))
<a name="l00121"></a>00121       <span class="keywordflow">return</span> 1;
<a name="l00122"></a>00122     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (currByte[0] == <span class="charliteral">&#39;9&#39;</span>)
<a name="l00123"></a>00123       <span class="keywordflow">return</span> 2;
<a name="l00124"></a>00124   }
<a name="l00125"></a>00125   <span class="keywordflow">return</span> 0;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 <span class="comment"></span>
<a name="l00129"></a>00129 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00130"></a>00130 <span class="comment"></span><span class="comment">//</span>
<a name="l00131"></a>00131 <span class="comment">//      Echo All Input Off - Turns off the echo effect on the wifi.</span>
<a name="l00132"></a>00132 <span class="comment">//      Sending the serial command &quot;ate0&quot; which turns off the echo effect.</span>
<a name="l00133"></a>00133 <span class="comment">//      Sends one single byte at a time, pauses.</span>
<a name="l00134"></a>00134 <span class="comment">//      Drains receiver with a read each time.</span>
<a name="l00135"></a>00135 <span class="comment">//</span><span class="comment"></span>
<a name="l00136"></a>00136 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00137"></a>00137 <span class="comment"></span>
<a name="l00138"></a><a class="code" href="dexterind-wifi_8h.html#a048eb7ed3aa696ce6ec76234ef5f721c">00138</a> <span class="keywordtype">void</span> <a class="code" href="dexterind-wifi_8h.html#a048eb7ed3aa696ce6ec76234ef5f721c">DWIFIsetEcho</a>(<span class="keywordtype">bool</span> on)
<a name="l00139"></a>00139 {
<a name="l00140"></a>00140   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetEcho&quot;</span>);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142   ubyte nData[] = {<span class="charliteral">&#39;A&#39;</span>,<span class="charliteral">&#39;T&#39;</span>,<span class="charliteral">&#39;E&#39;</span>,<span class="charliteral">&#39;0&#39;</span>,0x0A};
<a name="l00143"></a>00143   <span class="keywordflow">if</span> (on)
<a name="l00144"></a>00144   {
<a name="l00145"></a>00145     nData[3] = <span class="charliteral">&#39;1&#39;</span>;
<a name="l00146"></a>00146   }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; 5; i++){
<a name="l00149"></a>00149     nxtWriteRawHS(&amp;nData[i], 1);            <span class="comment">// Send the command, byte by byte.</span>
<a name="l00150"></a>00150     nxtReadRawHS(&amp;<a class="code" href="dexterind-wifi_8h.html#a9e6f17494d1421464ef6545fba911512">BytesRead</a>[0], 8);         <span class="comment">// Clear out the echo.</span>
<a name="l00151"></a>00151     wait1Msec(100);
<a name="l00152"></a>00152   }
<a name="l00153"></a>00153   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00154"></a>00154 }
<a name="l00155"></a>00155 
<a name="l00156"></a>00156 
<a name="l00157"></a><a class="code" href="dexterind-wifi_8h.html#a71a0978be2c62bd2c768a465838b1e4c">00157</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a71a0978be2c62bd2c768a465838b1e4c">DWIFIsetVerbose</a>(<span class="keywordtype">bool</span> on)
<a name="l00158"></a>00158 {
<a name="l00159"></a>00159   <span class="keywordtype">bool</span> res;
<a name="l00160"></a>00160   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetVerbose&quot;</span>);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162   <span class="keywordflow">if</span> (on)
<a name="l00163"></a>00163     res = <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;ATV1\n&quot;</span>);
<a name="l00164"></a>00164   <span class="keywordflow">else</span>
<a name="l00165"></a>00165     res = <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;ATV0\n&quot;</span>);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167   <span class="keywordflow">if</span> (!res)
<a name="l00168"></a>00168     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;DWIFIsetVerbose&quot;</span>);
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173 <span class="comment"></span>
<a name="l00174"></a>00174 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00175"></a>00175 <span class="comment"></span><span class="comment">//</span>
<a name="l00176"></a>00176 <span class="comment">//      Software Flow Control On</span>
<a name="l00177"></a>00177 <span class="comment">//      Send string &quot;at&amp;k1&quot; and carriage return.</span>
<a name="l00178"></a>00178 <span class="comment">//      Shouldn&#39;t need the wait or read now that we&#39;ve got the echo off.</span>
<a name="l00179"></a>00179 <span class="comment">//</span><span class="comment"></span>
<a name="l00180"></a>00180 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00181"></a>00181 <span class="comment"></span>
<a name="l00182"></a><a class="code" href="dexterind-wifi_8h.html#a2563f9c28a6b60bd91390770aca12fdf">00182</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a2563f9c28a6b60bd91390770aca12fdf">DWIFIsetSWControl</a>()
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184   <span class="comment">//DWIFIscratchString = &quot;AT&amp;K1\n&quot;;</span>
<a name="l00185"></a>00185   <span class="comment">//memcpy(RS485txbuffer, DWIFIscratchString, strlen(DWIFIscratchString));</span>
<a name="l00186"></a>00186   <span class="comment">//return RS485write(RS485txbuffer, strlen(DWIFIscratchString));</span>
<a name="l00187"></a>00187   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT&amp;K1\n&quot;</span>))
<a name="l00188"></a>00188     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00189"></a>00189 
<a name="l00190"></a>00190   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;DWIFIsetSWControl&quot;</span>);
<a name="l00191"></a>00191 
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 <span class="comment"></span>
<a name="l00194"></a>00194 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00195"></a>00195 <span class="comment"></span><span class="comment">//</span>
<a name="l00196"></a>00196 <span class="comment">//      Scan for networks</span>
<a name="l00197"></a>00197 <span class="comment">//      Send string &quot;AT+WS&quot; and carriage return.</span>
<a name="l00198"></a>00198 <span class="comment">//      Don&#39;t really need to do this; gets back a tonne of data.</span>
<a name="l00199"></a>00199 <span class="comment">//</span><span class="comment"></span>
<a name="l00200"></a>00200 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00201"></a>00201 <span class="comment"></span>
<a name="l00202"></a><a class="code" href="dexterind-wifi_8h.html#ad7a94b56cb6baf74a090130e5cb06c9d">00202</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#ad7a94b56cb6baf74a090130e5cb06c9d">DWIFIscanNetworks</a>()
<a name="l00203"></a>00203 {
<a name="l00204"></a>00204   <span class="comment">//DWIFIscratchString = &quot;AT+ws\n&quot;;</span>
<a name="l00205"></a>00205   <span class="comment">//memcpy(RS485txbuffer, DWIFIscratchString, strlen(DWIFIscratchString));</span>
<a name="l00206"></a>00206   <span class="comment">//return RS485write(RS485txbuffer, strlen(DWIFIscratchString));</span>
<a name="l00207"></a>00207   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+ws\n&quot;</span>);
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 <span class="comment"></span>
<a name="l00210"></a>00210 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00211"></a>00211 <span class="comment"></span><span class="comment">//</span>
<a name="l00212"></a>00212 <span class="comment">//      WIFI:  Set Authentication Mode</span>
<a name="l00213"></a>00213 <span class="comment">//             Send string &quot;at+wauth=&lt;n&gt;&quot; and carriage return.</span>
<a name="l00214"></a>00214 <span class="comment">//              n = 0 --&gt; Off</span>
<a name="l00215"></a>00215 <span class="comment">//              n = 1 --&gt; On</span>
<a name="l00216"></a>00216 <span class="comment">//</span><span class="comment"></span>
<a name="l00217"></a>00217 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00218"></a>00218 <span class="comment"></span>
<a name="l00219"></a><a class="code" href="dexterind-wifi_8h.html#ab1f316399fc8e8dcd5c889db05358613">00219</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#ab1f316399fc8e8dcd5c889db05358613">DWIFIsetAuthMode</a>(<span class="keywordtype">int</span> state)
<a name="l00220"></a>00220 {
<a name="l00221"></a>00221   <span class="keywordflow">if</span> (state == 0)
<a name="l00222"></a>00222     <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+WAUTH=0\n&quot;</span>);
<a name="l00223"></a>00223   <span class="keywordflow">else</span>
<a name="l00224"></a>00224     <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+WAUTH=1\n&quot;</span>);
<a name="l00225"></a>00225 }
<a name="l00226"></a>00226 
<a name="l00227"></a>00227 <span class="comment"></span>
<a name="l00228"></a>00228 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00229"></a>00229 <span class="comment"></span><span class="comment">//</span>
<a name="l00230"></a>00230 <span class="comment">//      WIFI:  Set WEP key.</span>
<a name="l00231"></a>00231 <span class="comment">//             Send string &quot;at+WWEPn=&lt;m&gt;&quot; and carriage return.</span>
<a name="l00232"></a>00232 <span class="comment">//</span>
<a name="l00233"></a>00233 <span class="comment">//                  m = WEP Key.</span>
<a name="l00234"></a>00234 <span class="comment">//                  n = type of WEP key.</span>
<a name="l00235"></a>00235 <span class="comment">//                        n= 0</span>
<a name="l00236"></a>00236 <span class="comment">//                        n= 1</span>
<a name="l00237"></a>00237 <span class="comment">//                        n= 2</span>
<a name="l00238"></a>00238 <span class="comment">//</span><span class="comment"></span>
<a name="l00239"></a>00239 <span class="comment">////////////////////////////////////////////////////////////////////////////////////////////////////////</span>
<a name="l00240"></a>00240 <span class="comment"></span>
<a name="l00241"></a><a class="code" href="dexterind-wifi_8h.html#a45d94e1a97d0ced00a05a3f56dd85e04">00241</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a45d94e1a97d0ced00a05a3f56dd85e04">DWIFIsetSSID</a>(<span class="keywordtype">char</span> *_ssid)
<a name="l00242"></a>00242 {
<a name="l00243"></a>00243   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetSSID&quot;</span>);
<a name="l00244"></a>00244   <span class="keywordtype">char</span> *ssid_cmd = &amp;<a class="code" href="dexterind-wifi_8h.html#a92597d8032c00de74b8f7e830f6b9e2e">DWIFIscratchArray</a>;
<a name="l00245"></a>00245   memset(ssid_cmd, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a>));
<a name="l00246"></a>00246   sprintf(ssid_cmd, <span class="stringliteral">&quot;AT+WA=%s\n&quot;</span>, _ssid);
<a name="l00247"></a>00247   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(ssid_cmd);
<a name="l00248"></a>00248   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, 500, <span class="stringliteral">&quot;DWIFIsetSSID&quot;</span>);
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 
<a name="l00252"></a><a class="code" href="dexterind-wifi_8h.html#a4bf26d56aba7c67e7a0f2e713de2ed4f">00252</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a4bf26d56aba7c67e7a0f2e713de2ed4f">DWIFIsetWEPKey</a>(<span class="keywordtype">int</span> keyindex, <span class="keywordtype">char</span> *_wep_key)
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetWEPKey&quot;</span>);
<a name="l00255"></a>00255   <span class="keywordtype">char</span> *set_wep_psk_cmd = &amp;<a class="code" href="dexterind-wifi_8h.html#a92597d8032c00de74b8f7e830f6b9e2e">DWIFIscratchArray</a>;
<a name="l00256"></a>00256   memset(set_wep_psk_cmd, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a>));
<a name="l00257"></a>00257   sprintf(set_wep_psk_cmd, <span class="stringliteral">&quot;AT+WWEP%d=%s\n&quot;</span>, keyindex, _wep_key);
<a name="l00258"></a>00258   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(set_wep_psk_cmd);
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 
<a name="l00262"></a><a class="code" href="dexterind-wifi_8h.html#a67ee7d70024d0028047ed2fd6793980e">00262</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a67ee7d70024d0028047ed2fd6793980e">DWIFIsetWPAPSK</a>(<span class="keywordtype">char</span> *ssid, <span class="keywordtype">char</span> *_wpa_key)
<a name="l00263"></a>00263 {
<a name="l00264"></a>00264   <span class="keywordtype">int</span> len;
<a name="l00265"></a>00265   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetWPAPSK&quot;</span>);
<a name="l00266"></a>00266 
<a name="l00267"></a>00267   <span class="keywordtype">char</span> *set_wpa_psk_cmd = &amp;<a class="code" href="dexterind-wifi_8h.html#a92597d8032c00de74b8f7e830f6b9e2e">DWIFIscratchArray</a>;
<a name="l00268"></a>00268   memset(set_wpa_psk_cmd, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gacc2928041c5ff8e7f2ddef1e88431e80">tHugeByteArray</a>));
<a name="l00269"></a>00269   sprintf(set_wpa_psk_cmd, <span class="stringliteral">&quot;AT+WPAPSK=%s,%s\n&quot;</span>, ssid, _wpa_key);
<a name="l00270"></a>00270   <span class="keywordflow">if</span> (!<a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(set_wpa_psk_cmd))
<a name="l00271"></a>00271     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00272"></a>00272   <span class="comment">//RS485read(RS485rxbuffer, len, 50);</span>
<a name="l00273"></a>00273   wait1Msec(100);
<a name="l00274"></a>00274   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00275"></a>00275   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, 30000, <span class="stringliteral">&quot;DWIFIsetWPAPSK&quot;</span>);
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277 
<a name="l00278"></a><a class="code" href="dexterind-wifi_8h.html#a2da6de10f8edb354069d61d241a4ebe7">00278</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a2da6de10f8edb354069d61d241a4ebe7">DWIFIsetDHCP</a>(<span class="keywordtype">bool</span> useDHCP)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280   <span class="keywordflow">if</span> (useDHCP)
<a name="l00281"></a>00281     <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+NDHCP=1\n&quot;</span>);
<a name="l00282"></a>00282   <span class="keywordflow">else</span>
<a name="l00283"></a>00283     <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+NDHCP=0\n&quot;</span>);
<a name="l00284"></a>00284 
<a name="l00285"></a>00285   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, 1000, <span class="stringliteral">&quot;DWIFIsetDHCP&quot;</span>);
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a><a class="code" href="dexterind-wifi_8h.html#ab875f6364aab841607eaeb7abaf1147c">00288</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#ab875f6364aab841607eaeb7abaf1147c">getFW</a>()
<a name="l00289"></a>00289 {
<a name="l00290"></a>00290   writeDebugStreamLine(<span class="stringliteral">&quot;getFW&quot;</span>);
<a name="l00291"></a>00291   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+VER=?\n&quot;</span>);
<a name="l00292"></a>00292 }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 
<a name="l00295"></a><a class="code" href="dexterind-wifi_8h.html#ae470b5981a953e967c086902b7104145">00295</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#ae470b5981a953e967c086902b7104145">getInfo</a>() {
<a name="l00296"></a>00296   writeDebugStreamLine(<span class="stringliteral">&quot;getInfo&quot;</span>);
<a name="l00297"></a>00297   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+NSTAT=?\n&quot;</span>);
<a name="l00298"></a>00298 }
<a name="l00299"></a>00299 
<a name="l00300"></a><a class="code" href="dexterind-wifi_8h.html#a4534fad19e55b4fd20a1ea6d3a43d1d7">00300</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a4534fad19e55b4fd20a1ea6d3a43d1d7">getInfoWLAN</a>() {
<a name="l00301"></a>00301   writeDebugStreamLine(<span class="stringliteral">&quot;getInfo&quot;</span>);
<a name="l00302"></a>00302   <span class="keywordflow">return</span> <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+WSTATUS\n&quot;</span>);
<a name="l00303"></a>00303 }
<a name="l00304"></a>00304 
<a name="l00305"></a><a class="code" href="dexterind-wifi_8h.html#a506eb6c77588a67959852def3c084687">00305</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a506eb6c77588a67959852def3c084687">DWIFIClose</a>(<span class="keywordtype">int</span> cid = -1) {
<a name="l00306"></a>00306   <span class="keywordtype">int</span> len;
<a name="l00307"></a>00307   <span class="keywordtype">bool</span> res;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIClose&quot;</span>);
<a name="l00310"></a>00310 
<a name="l00311"></a>00311   <span class="keywordflow">if</span> (cid &lt; 0)
<a name="l00312"></a>00312     res = <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT+NCLOSEALL\n&quot;</span>);
<a name="l00313"></a>00313   <span class="keywordflow">else</span>
<a name="l00314"></a>00314   {
<a name="l00315"></a>00315     StringFormat(<a class="code" href="dexterind-wifi_8h.html#af42cc903eee7724d9b68fdaedbdcf312">DWIFIscratchString</a>, <span class="stringliteral">&quot;AT+NCLOSE=%d\n&quot;</span>, cid);
<a name="l00316"></a>00316     res = <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<a class="code" href="dexterind-wifi_8h.html#af42cc903eee7724d9b68fdaedbdcf312">DWIFIscratchString</a>);
<a name="l00317"></a>00317   }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319   <span class="keywordflow">if</span> (!res)
<a name="l00320"></a>00320     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00321"></a>00321 
<a name="l00322"></a>00322   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;DWIFIClose&quot;</span>);
<a name="l00323"></a>00323   <span class="comment">//writeDebugStreamLine(&quot;closeAllCons&quot;);</span>
<a name="l00324"></a>00324   <span class="comment">//return RS485sendString(&quot;AT+NCLOSEALL\n&quot;);</span>
<a name="l00325"></a>00325 }
<a name="l00326"></a>00326 
<a name="l00327"></a>00327 <span class="comment">//bool closeConn(int cid) {</span>
<a name="l00328"></a>00328 <span class="comment">//  writeDebugStreamLine(&quot;closeConn&quot;);</span>
<a name="l00329"></a>00329 <span class="comment">//  StringFormat(DWIFIscratchString, &quot;AT+NCLOSE=%d\n&quot;, cid);</span>
<a name="l00330"></a>00330 <span class="comment">//  return RS485sendString(DWIFIscratchString);</span>
<a name="l00331"></a>00331 <span class="comment">//}</span>
<a name="l00332"></a>00332 
<a name="l00333"></a><a class="code" href="dexterind-wifi_8h.html#a7d76519531f8eb971b23ef724f3dca37">00333</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a7d76519531f8eb971b23ef724f3dca37">DWIFIsaveConfig</a>() {
<a name="l00334"></a>00334   <span class="keywordtype">int</span> len;
<a name="l00335"></a>00335   writeDebugStreamLine(<span class="stringliteral">&quot;save config&quot;</span>);
<a name="l00336"></a>00336   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT&amp;W0\n&quot;</span>);
<a name="l00337"></a>00337   <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;DWIFIsaveConfig W0&quot;</span>);
<a name="l00338"></a>00338   wait1Msec(500);
<a name="l00339"></a>00339   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT&amp;Y0\n&quot;</span>);
<a name="l00340"></a>00340   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;DWIFIsaveConfig Y0&quot;</span>);
<a name="l00341"></a>00341 }
<a name="l00342"></a>00342 
<a name="l00343"></a>00343 
<a name="l00344"></a><a class="code" href="dexterind-wifi_8h.html#a71587044996a578d207690ea86d6103d">00344</a> <span class="keywordtype">void</span> <a class="code" href="dexterind-wifi_8h.html#a71587044996a578d207690ea86d6103d">DWIFIresetConfig</a>()
<a name="l00345"></a>00345 {
<a name="l00346"></a>00346   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT&amp;F\n&quot;</span>);
<a name="l00347"></a>00347   wait1Msec(100);
<a name="l00348"></a>00348   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00349"></a>00349 }
<a name="l00350"></a>00350 
<a name="l00351"></a><a class="code" href="dexterind-wifi_8h.html#a178d5ceb174f6a7c85e2b0d5a888b077">00351</a> <span class="keywordtype">void</span> <a class="code" href="dexterind-wifi_8h.html#a178d5ceb174f6a7c85e2b0d5a888b077">DWIFITCPOpenServer</a>(<span class="keywordtype">long</span> port) {
<a name="l00352"></a>00352   <span class="keywordtype">int</span> index = 0;
<a name="l00353"></a>00353   <span class="keywordtype">int</span> len = 0;
<a name="l00354"></a>00354 
<a name="l00355"></a>00355   <span class="keywordtype">string</span> listen_cmd;
<a name="l00356"></a>00356   StringFormat(listen_cmd, <span class="stringliteral">&quot;AT+NSTCP=%d\n&quot;</span>, port);
<a name="l00357"></a>00357   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(listen_cmd);
<a name="l00358"></a>00358   <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 
<a name="l00361"></a><a class="code" href="dexterind-wifi_8h.html#a36fcd4421711267eca4e418615200780">00361</a> <span class="keywordtype">bool</span> <a class="code" href="dexterind-wifi_8h.html#a36fcd4421711267eca4e418615200780">checkBaudRate</a>(<span class="keywordtype">long</span> baudrate)
<a name="l00362"></a>00362 {
<a name="l00363"></a>00363   <span class="comment">//int len = 0;</span>
<a name="l00364"></a>00364   <span class="comment">//char *tmpbuff;</span>
<a name="l00365"></a>00365   <span class="keywordtype">string</span> tmpString;
<a name="l00366"></a>00366   writeDebugStreamLine(<span class="stringliteral">&quot;testing baudrate: %d&quot;</span>, baudrate);
<a name="l00367"></a>00367   nxtDisableHSPort();
<a name="l00368"></a>00368   wait1Msec(10);
<a name="l00369"></a>00369   nxtEnableHSPort();
<a name="l00370"></a>00370   nxtSetHSBaudRate(baudrate);
<a name="l00371"></a>00371   nxtHS_Mode = hsRawMode;
<a name="l00372"></a>00372   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00373"></a>00373   wait1Msec(100);
<a name="l00374"></a>00374   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;+++\n&quot;</span>);
<a name="l00375"></a>00375   wait1Msec(1000);
<a name="l00376"></a>00376   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00377"></a>00377   wait1Msec(100);
<a name="l00378"></a>00378   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(<span class="stringliteral">&quot;AT\n&quot;</span>);
<a name="l00379"></a>00379   <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#a0bd1508925610fb26d4e947bfd3546a8">DWIFIcheckResult</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, <span class="stringliteral">&quot;checkBaudRate&quot;</span>);
<a name="l00380"></a>00380 }
<a name="l00381"></a>00381 
<a name="l00382"></a><a class="code" href="dexterind-wifi_8h.html#a4266629fa8902934357c3e3d33775f13">00382</a> <span class="keywordtype">long</span> <a class="code" href="dexterind-wifi_8h.html#a4266629fa8902934357c3e3d33775f13">DWIFIscanBaudRate</a>() {
<a name="l00383"></a>00383   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; i++) {
<a name="l00384"></a>00384     <span class="keywordflow">if</span> (<a class="code" href="dexterind-wifi_8h.html#a36fcd4421711267eca4e418615200780">checkBaudRate</a>(<a class="code" href="dexterind-wifi_8h.html#accd447f37bc9ab0177af50148fee91b0">DWIFI_baudRates</a>[i]))
<a name="l00385"></a>00385     {
<a name="l00386"></a>00386       <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00387"></a>00387       <span class="keywordflow">return</span> <a class="code" href="dexterind-wifi_8h.html#accd447f37bc9ab0177af50148fee91b0">DWIFI_baudRates</a>[i];
<a name="l00388"></a>00388     }
<a name="l00389"></a>00389   }
<a name="l00390"></a>00390   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00391"></a>00391   <span class="keywordflow">return</span> 0;
<a name="l00392"></a>00392 }
<a name="l00393"></a>00393 
<a name="l00394"></a>00394 
<a name="l00395"></a><a class="code" href="dexterind-wifi_8h.html#acfbaa78abcf33cc95dad838a52dd10c4">00395</a> <span class="keywordtype">void</span> <a class="code" href="dexterind-wifi_8h.html#acfbaa78abcf33cc95dad838a52dd10c4">DWIFIsetBAUDRate</a>(<span class="keywordtype">long</span> baudrate) {
<a name="l00396"></a>00396   <span class="keywordtype">int</span> index = 0;
<a name="l00397"></a>00397   <span class="keywordtype">long</span> current_baudrate = 0;
<a name="l00398"></a>00398 
<a name="l00399"></a>00399   <span class="keywordtype">string</span> baud_cmd;
<a name="l00400"></a>00400 
<a name="l00401"></a>00401   <span class="keywordflow">if</span> (<a class="code" href="dexterind-wifi_8h.html#a36fcd4421711267eca4e418615200780">checkBaudRate</a>(baudrate))
<a name="l00402"></a>00402   {
<a name="l00403"></a>00403     writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetBAUDRate: already correct&quot;</span>);
<a name="l00404"></a>00404     <span class="keywordflow">return</span>;
<a name="l00405"></a>00405   }
<a name="l00406"></a>00406 
<a name="l00407"></a>00407   current_baudrate = <a class="code" href="dexterind-wifi_8h.html#a4266629fa8902934357c3e3d33775f13">DWIFIscanBaudRate</a>();
<a name="l00408"></a>00408   <span class="keywordflow">if</span> (current_baudrate == 0)
<a name="l00409"></a>00409   {
<a name="l00410"></a>00410     writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetBAUDRate could not determine baudrate&quot;</span>);
<a name="l00411"></a>00411     <span class="keywordflow">return</span>;
<a name="l00412"></a>00412   }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414   StringFormat(baud_cmd, <span class="stringliteral">&quot;ATB=%d\n&quot;</span>, baudrate);
<a name="l00415"></a>00415   <a class="code" href="group__common-rs485.html#gadb0d2f59860d233f035b318570e80f06">RS485sendString</a>(baud_cmd);
<a name="l00416"></a>00416 
<a name="l00417"></a>00417   wait1Msec(100);
<a name="l00418"></a>00418   nxtDisableHSPort();
<a name="l00419"></a>00419   wait1Msec(10);
<a name="l00420"></a>00420   nxtEnableHSPort();
<a name="l00421"></a>00421   nxtSetHSBaudRate(baudrate);
<a name="l00422"></a>00422   nxtHS_Mode = hsRawMode;
<a name="l00423"></a>00423   wait1Msec(10);
<a name="l00424"></a>00424   <a class="code" href="group__common-rs485.html#ga4446a74148d4d8d4f387a3bb08080f85">RS485clearRead</a>();
<a name="l00425"></a>00425   wait1Msec(10);
<a name="l00426"></a>00426 
<a name="l00427"></a>00427   <span class="comment">// Verify the speed to ensure everything went OK</span>
<a name="l00428"></a>00428   <span class="keywordflow">if</span> (<a class="code" href="dexterind-wifi_8h.html#a36fcd4421711267eca4e418615200780">checkBaudRate</a>(baudrate))
<a name="l00429"></a>00429   {
<a name="l00430"></a>00430     writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetBAUDRate: reconfigured succesfully&quot;</span>);
<a name="l00431"></a>00431   }
<a name="l00432"></a>00432   <span class="keywordflow">else</span>
<a name="l00433"></a>00433   {
<a name="l00434"></a>00434     writeDebugStreamLine(<span class="stringliteral">&quot;DWIFIsetBAUDRate: reconfigured unsuccesfully&quot;</span>);
<a name="l00435"></a>00435   }
<a name="l00436"></a>00436 }
<a name="l00437"></a>00437 
<a name="l00438"></a>00438 <span class="comment">/*</span>
<a name="l00439"></a>00439 <span class="comment">    IP              SubNet         Gateway</span>
<a name="l00440"></a>00440 <span class="comment"> 192.168.178.26: 255.255.255.0: 192.168.178.1</span>
<a name="l00441"></a>00441 <span class="comment"> */</span>
<a name="l00442"></a><a class="code" href="dexterind-wifi_8h.html#a039e65088574663ef333e58befe6aa94">00442</a> <span class="keywordtype">void</span> <a class="code" href="dexterind-wifi_8h.html#a039e65088574663ef333e58befe6aa94">DWIFIwaitForIP</a>()
<a name="l00443"></a>00443 {
<a name="l00444"></a>00444   <span class="keywordtype">string</span> IPscratch;
<a name="l00445"></a>00445   <span class="keywordtype">char</span> *e_marker = <span class="stringliteral">&quot;Gateway&quot;</span>;
<a name="l00446"></a>00446   <span class="keywordtype">char</span> *token_begin = <span class="stringliteral">&quot; &quot;</span>;
<a name="l00447"></a>00447   <span class="keywordtype">char</span> *token_end = <span class="stringliteral">&quot;:&quot;</span>;
<a name="l00448"></a>00448 
<a name="l00449"></a>00449   <a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a> tmp_array;
<a name="l00450"></a>00450   <span class="keywordtype">int</span> len;
<a name="l00451"></a>00451   <span class="keywordtype">int</span> bpos;
<a name="l00452"></a>00452   <span class="keywordtype">int</span> epos;
<a name="l00453"></a>00453   <span class="keywordtype">bool</span> parsed = <span class="keyword">true</span>;
<a name="l00454"></a>00454   <span class="keywordtype">int</span> startIPinfo = 0;
<a name="l00455"></a>00455   <span class="keywordtype">int</span> nextTokenStart = 0;
<a name="l00456"></a>00456   writeDebugStreamLine(<span class="stringliteral">&quot;Beging parsing...&quot;</span>);
<a name="l00457"></a>00457   ubyte conn[] = {0};
<a name="l00458"></a>00458   <span class="keywordtype">int</span> index = 0;
<a name="l00459"></a>00459   memset(&amp;tmp_array[0], 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a>));
<a name="l00460"></a>00460   <span class="keywordflow">while</span> (<span class="keyword">true</span>)
<a name="l00461"></a>00461   {
<a name="l00462"></a>00462     <a class="code" href="group__common-rs485.html#gaaf7c3831c4bf35f0a581890749bd8b0e">RS485read</a>(<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>, len, 100);
<a name="l00463"></a>00463     <span class="keywordflow">if</span> (len &gt; 0)
<a name="l00464"></a>00464     {
<a name="l00465"></a>00465       writeDebugStreamLine(<span class="stringliteral">&quot;Appending to buffer: %d&quot;</span>, len);
<a name="l00466"></a>00466       parsed = <span class="keyword">false</span>;
<a name="l00467"></a>00467       <span class="keywordflow">if</span> (index == 0)
<a name="l00468"></a>00468         memset(&amp;tmp_array[0], 0, <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a>));
<a name="l00469"></a>00469 
<a name="l00470"></a>00470       index = <a class="code" href="group__common-rs485.html#ga8cc30dfc87646c9abff0265a7c254261">RS485appendToBuff</a>(tmp_array, index, &amp;<a class="code" href="group__common-rs485.html#gae1645d814439623db869c5bfb5d4bd32">RS485rxbuffer</a>[0], len);
<a name="l00471"></a>00471     }
<a name="l00472"></a>00472     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((parsed == <span class="keyword">false</span>) &amp;&amp; (len == 0))
<a name="l00473"></a>00473     {
<a name="l00474"></a>00474       writeDebugStreamLine(<span class="stringliteral">&quot;Parsing buffer: %s&quot;</span>, &amp;tmp_array[0]);
<a name="l00475"></a>00475       epos = <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)&amp;tmp_array[0], &amp;e_marker[0]);
<a name="l00476"></a>00476       <span class="comment">// we&#39;ve found a start and end marker</span>
<a name="l00477"></a>00477 
<a name="l00478"></a>00478       <span class="keywordflow">if</span> (epos &gt; -1)
<a name="l00479"></a>00479       {
<a name="l00480"></a>00480         writeDebugStreamLine(<span class="stringliteral">&quot;end marker found: %d&quot;</span>, epos);
<a name="l00481"></a>00481         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 3; i++)
<a name="l00482"></a>00482         {
<a name="l00483"></a>00483           writeDebugStreamLine(<span class="stringliteral">&quot;nextTokenStart: %d&quot;</span>, nextTokenStart);
<a name="l00484"></a>00484           nextTokenStart = epos;
<a name="l00485"></a>00485           memmove((<span class="keywordtype">char</span> *)&amp;tmp_array[0], (<span class="keywordtype">char</span> *)&amp;tmp_array[nextTokenStart], <span class="keyword">sizeof</span>(<a class="code" href="group__common.html#gaf1da7edf6615d1b2376642de9bbfe449">tMassiveArray</a>) - nextTokenStart);
<a name="l00486"></a>00486           bpos = <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)&amp;tmp_array[0], token_begin);
<a name="l00487"></a>00487           epos = <a class="code" href="group___n_x_t2_w_i_f_i.html#gac9623873538026c63a3f80d3f41a787f">StringFind</a>((<span class="keywordtype">char</span> *)&amp;tmp_array[0], token_end);
<a name="l00488"></a>00488           <span class="keywordflow">if</span> (bpos &gt; -1 &amp;&amp; epos &gt; -1)
<a name="l00489"></a>00489                       {
<a name="l00490"></a>00490                         writeDebugStreamLine(<span class="stringliteral">&quot;IP bpos: %d, epos: %d&quot;</span>, bpos, epos);
<a name="l00491"></a>00491                         memcpy(IPscratch, (<span class="keywordtype">char</span> *)&amp;tmp_array[bpos], epos - bpos);
<a name="l00492"></a>00492                         writeDebugStreamLine(<span class="stringliteral">&quot;IPinfo: %s&quot;</span>, IPscratch);
<a name="l00493"></a>00493                       }
<a name="l00494"></a>00494         }
<a name="l00495"></a>00495       }
<a name="l00496"></a>00496       <span class="keywordflow">else</span>
<a name="l00497"></a>00497       {
<a name="l00498"></a>00498         writeDebugStreamLine(<span class="stringliteral">&quot;no markers found&quot;</span>);
<a name="l00499"></a>00499       }
<a name="l00500"></a>00500       parsed = <span class="keyword">true</span>;
<a name="l00501"></a>00501       index = 0;
<a name="l00502"></a>00502       wait1Msec(2000);
<a name="l00503"></a>00503       PlaySound(soundBeepBeep);
<a name="l00504"></a>00504     }
<a name="l00505"></a>00505         }
<a name="l00506"></a>00506 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
